package cn.echo.hrm.exception;

import java.util.List;

/**
 * 断言类，断言某个条件不满足就抛出异常
 */
public class Assert {

    //断言不为null
    public static void assertNotNull(Object obj, String message){
        if (obj == null){
            throw new BusinessException(message);
        }
    }

    //断言不为空
    public static void assertNotEmpty(String s, String message){
        if (s == null || s.trim().equals("")){
            throw new BusinessException(message);
        }
    }

    //断言为null
    public static void assertNull(Object o, String message){
        if (o != null){
            throw new BusinessException(message);
        }
    }

    //断言list不为null
    public static void assertListNotNull(List<?> list, String message){
        if (list == null || list.size()<1){
            throw new BusinessException(message);
        }
    }

    //断言数组不为null
    public static void assertArrayNotNull(Object[] arr, String message){
        if (arr == null || arr.length<1){
            throw new BusinessException(message);
        }
    }

    //断言数组为null
    public static void assertArrayNull(Object[] arr, String message){
        if (arr == null || arr.length>0){
            throw new BusinessException(message);
        }
    }

    //断言list为null
    public static void assertListNull(List<?> list, ErrorCode errorCode){
        if (list == null || list.size()>0){
            throw new BusinessException(errorCode);
        }
    }

    //断言为ture
    public static void assertTrue(boolean b, String message){
        if (!b){
            throw new BusinessException(message);
        }
    }

    //断言为false
    public static void assertFalse(boolean b, String message){
        if (b){
            throw new BusinessException(message);
        }
    }
}
